﻿using QLKetNoi;
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QLDVu.BO
{
    public class DanhSachHangHoaBO
    {
        public static Table<HANGHOA> DanhSachHangHoa()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            return dulieu.GetTable<HANGHOA>();

        }
        public static HANGHOA HangHoaCuoiCung()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            HANGHOA s = dulieu.HANGHOAs.OrderByDescending(hh => hh.MaHangHoa).FirstOrDefault();
            return s;

        }
        public static HANGHOA DanhSachHangHoa(string mahanghoa)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<HANGHOA> hanghoa = dulieu.GetTable<HANGHOA>();
            HANGHOA x = hanghoa.Single(hh => hh.MaHangHoa.Equals(mahanghoa));
            return x;

        }
        public static Table<LOAIHANGHOA> DanhSachLoaiHangHoa()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            return dulieu.GetTable<LOAIHANGHOA>();

        }
        public static Table<NHACUNGCAP> DanhSachNhaCungCap()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            return dulieu.GetTable<NHACUNGCAP>();

        }
        public static Table<DONVITINH> DanhSachDonViTinh()
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            return dulieu.GetTable<DONVITINH>();

        }
        public static void ThemHangHoa(string mahanghoa, string tenhanghoa, string maloaihanghoa,
            string manhacungcap, string xuatxu, string mavach, string madonvitinh,string thoigianbaohanh,
            string mota,string anh)
        {
            QLDNDataContext dulieu = new QLDNDataContext();
            Table<HANGHOA> hanghoa = dulieu.GetTable<HANGHOA>();
            HANGHOA hh = new HANGHOA();
            hh.MaHangHoa = mahanghoa;
            hh.TenHangHoa = tenhanghoa;
            hh.MaLoaiHangHoa = maloaihanghoa;
            hh.MaNhaCungCap = manhacungcap;
            hh.XuatXu = xuatxu;
            hh.MaVach = mavach;
            hh.MaDonViTinh = madonvitinh;
            hh.ThoiGianBaoHanh =Convert.ToInt32(thoigianbaohanh);
            hh.MoTa = mota;
            hh.ConQuanLy = true;
            hanghoa.InsertOnSubmit(hh);
            dulieu.SubmitChanges();

        }
    }
}
